import myclass

import copy

def linecount(filename):
    count=0
    for line in open(filename):
        count+=1
    return count

def has_no_e(word):
    for letter in word:
        if letter=='e':
            return False
    return True

def avoids(word,str):
    for letter in str:
        if letter in word:
            return False
    return True

def uses_only(word,str):
    for letter in word:
        if letter not in str:
            return False
    return True

def uses_all(word,str):
    for letter in str:
        if letter not in word:
            return False
    return True

def is_abecedarian(word):
    length=len(word)
    if length<=1:
        return True
    for i in range(0,length-1):
        if word[i]>word[i+1]:
             return False
    return True

def is_three_serial_word(word):
    length=len(word)
    if length<6:
        return False
    a=[]
    for i in range(0,length-1):
        if word[i]==word[i+1]:
            a.append(i)
    if len(a)<3:
        return False
    for j in range(1,len(a)-1):
        if a[j]-a[j-1]==2 and a[j+1]-a[j]==2:
            return True
    return False

def is_plaindrome(number):
    i=0
    j=len(number)-1
    while i<j:
        if number[i]!=number[j]:
            return False
        i=i+1
        j=j-1
    return True

def nested_sum(t):
    total=0
    for a in t:
        total+=sum(a)
    return total

def is_sorted(t):
    if len(t)<=1:
        return True
    for i in range(len(t)-1):
        if t[i]>t[i+1]:
            return False
    return True

def histogram(s):
    d={}
    for c in s:
        a=d.get(c,0)
        a+=1
        d[c]=a
    return d

def invert_dict(d):
    inverse=dict()
    for key in d:
        val=d[key]
        if val not in inverse:
            inverse[val]=[key]
        else:
            inverse[val].append(key)
    return inverse

def fibonacci1(n):
    if n==0:
        return 0
    if n==1:
        return 1
    res=fibonacci1(n-1)+fibonacci1(n-2)
    return res

def fibonacci2(n,known):
    if n in known:
        return known[n]
    else:
        res=fibonacci2(n-1)+fibonacci2(n-2)
        known[n]=res
        return res

def fact(n,A):
    if n in A:
        return A[n]
    res=n*fact(n-1)
    A[n]=res
    return res

def fact2(n):
    if n<=2:
        return n
    res=n*fact2(n-1)
    return res

def magic(n):
    count=0
    if n==0:
        return (0,count)
    else:
        while n!=1:
            if n%2==0:
                n=n/2
            else:
                n=n*3+1
            count+=1
        return (4,count)

def is_after(T1,T2):
    a=(T1.hour,T1.minute,T1.second)
    b=(T2.hour,T2.minute,T2.second)
    return a<b

def increment(t,seconds):
    T=module1.Time()
    T.hour=t.hour
    T.minute=t.minute
    T.second=t.second
    T.second+=seconds
    if T.second>=60:
        m,T.second=divmod(T.second,60)
        T.minute+=m
        if T.minute>=60:
            h,T.minute=divmod(T.minute,60)
            T.hour+=h
    return T